function TreeComboView(div, config, items) {

	var self = this;
	var cfg = copyConfig({
		dropDownWidth: 100,
		dropDownHeight: 25,
		title: 'items',
		idProp: 'id',
		nameProp: 'name',
		parentProp: 'parentId',
		requestEvent: 'items-request',
		updateEvent: 'items-loaded'
	}, config);
	this.itemsMap = {};
	this.checkedItems = [];
	this.changeTimer = null;

	function TreeSource(items) {
		this.localdata = items;
		this.datatype = "array";
		this.datafields = [
			{ name: cfg.idProp },
			{ name: cfg.nameProp, type: 'string' },
			{ name: cfg.parentProp }
		];
		this.id = cfg.idProp;
	};

	$.subscribe(cfg.updateEvent, function (event, data) {
		self.updateItems(data.items);
	});

	var self = this;
	el(div).html('<div id="' + div + 'DropDown"><div id="' + div + 'Tree"></div></div>');
	el(div + 'DropDown').jqxDropDownButton({ width: cfg.dropDownWidth, height: cfg.dropDownHeight });
	el(div + 'DropDown').jqxDropDownButton('setContent', '<div style="position: relative; margin-left: 3px; margin-top: 5px;">' + cfg.title + '</div>');
	el(div + 'Tree').jqxTree({ checkboxes: false, hasThreeStates: true });

	var findParent = function(parentsMap, map, item) {
		var parentId = item[cfg.parentProp];
		if(item[cfg.parentProp] in parentsMap) {
			return true;
		} else if(parentId != null && (parentId in map)) {
			var parent = map[parentId];
			return findParent(parentsMap, map, parent);
		}
		return false;
	};

	this.updateItems = function(items) {
		this.itemsMap = {};
		$.each(items, function(index, item) {
			self.itemsMap[item[cfg.idProp]] = item;
		}) ;
		var itemsSource = new TreeSource(items);
		var itemsAdapter = new $.jqx.dataAdapter(itemsSource);
		itemsAdapter.dataBind();
		var records = itemsAdapter.getRecordsHierarchy(cfg.idProp, cfg.parentProp, 'items', [{ name: cfg.nameProp, map: 'label' }])

		el(div + 'Tree').jqxTree({ source: records });
		el(div + 'Tree').jqxTree('expandAll');
	};

	this.onChange = function() {
		var items = el(div + 'Tree').jqxTree('getCheckedItems');
		this.checkedItems = [];
		var parentsMap = {};
		$.each(items, function(index, item) {
			parentsMap[item[cfg.idProp]] = item;
		});
		$.each(items, function(index, item) {
			if(!findParent(parentsMap, self.itemsMap, item)) {
				self.checkedItems.push(self.itemsMap[item[cfg.idProp]]);
			}
		});
		$(self).trigger('change', { items: this.checkedItems });
	};

	this.selectIds = function(itemIdsMap) {
		var items = el(div + 'Tree').jqxTree('getItems');
		$.each(items, function(index, item) {
			if(item.id in itemIdsMap) {
				el(div + 'Tree').jqxTree('checkItem', item, true);
			}
		});
	};

	this.updateItems(items);
	el(div + 'Tree').on('checkChange', function(event) {
		clearTimeout(self.changeTimer);
		self.changeTimer = setTimeout(function() { self.onChange(); }, 200);
	});
};